using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using ProduceBasicData.Api.Application.Command.Dashboard;
using ProduceBasicData.Api.DTO;
using ProduceBasicData.ErrorCode;

namespace ProduceBasicData.Api.Controllers
{
    /// <summary>
    /// 仪表板数据控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class DashboardController : ControllerBase
    {
        private readonly IMediator mediator;

        public DashboardController(IMediator mediator)
        {
            this.mediator = mediator;
        }

        /// <summary>
        /// 获取仪表板数据接口
        /// </summary>
        /// <param name="request">查询参数</param>
        /// <returns>仪表板数据</returns>
        [HttpGet]
        public async Task<ApiResult<DashboardDto>> GetDashboardData([FromQuery] GetDashboardDataCommand request)
        {
            return await mediator.Send(request);
        }

        /// <summary>
        /// 获取仪表板数据接口（简化版本，无参数）
        /// </summary>
        /// <returns>仪表板数据</returns>
        [HttpGet]
        public async Task<ApiResult<DashboardDto>> GetDashboardDataSimple()
        {
            var request = new GetDashboardDataCommand
            {
                IncludeChartData = true,
                ChartDataDays = 30
            };
            return await mediator.Send(request);
        }
    }
}
